﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Drawing;
using Intorise.Common;
using System.Diagnostics;

namespace Model
{
    public partial class Player
    {
        ManualResetEvent initEvent = new ManualResetEvent(false);
        MissionBase currentRunMission = null;
        int missionMoveTimeout = 120;

        #region 任务消息处理
        public bool ProcessMissionData(Message x)
        {
            //return true;
            GameHelper.RunGameThread(() =>
            {
                if (!initEvent.WaitOne(1 * 60 * 1000))
                {
                    ConsoleBLL.WriteLineError(this + "初始化超时..."); return;
                }
                if (x.Data[0] == 0 || this.Level < 150)
                {
                    GameHelper.RunGameThread(PlayAutoFight); return;
                }
                var datas = x.Data.Skip(29).ToArray();
                var count = net.GetHostInt16(datas);//任务数量

                if (this.Level >= 160 && !Tools.Search(datas, datas.Length, new byte[] { 0xD4, 0x9D, 0x01, 0x01 }))
                {
                    missions.色即是空.IsCompleted = true;
                }
                if (this.Level >= 160 && !Tools.Search(datas, datas.Length, new byte[] { 0xEE, 0xD5, 0x56 }))
                {
                    missions.破损的魔导师铠甲.IsCompleted = missions.色即是空.IsCompleted;
                }
                if (this.Level >= 160 && !Tools.Search(datas, datas.Length, missions.使用微端登录.IDByte))
                {
                    missions.使用微端登录.IsCompleted = missions.破损的魔导师铠甲.IsCompleted;
                }
                if (missions.使用微端登录.IsCompleted && !Tools.Search(datas, datas.Length, missions.快速升级.IDByte))
                {
                    missions.快速升级.IsCompleted = true;
                }

                if (this.Level >= 150 && !Tools.Search(datas, datas.Length, missions.转职.IDByte))
                {
                    missions.转职.IsCompleted = true;
                }
                if (this.Level >= 150 && !Tools.Search(datas, datas.Length, missions.转职_帝王之书.IDByte))
                {
                    missions.转职_帝王之书.IsCompleted = missions.转职.IsCompleted;
                }
                if (this.Level >= 150 && !Tools.Search(datas, datas.Length, missions.转职_先知之魂.IDByte))
                {
                    missions.转职_先知之魂.IsCompleted = missions.转职_帝王之书.IsCompleted;
                }


                foreach (var m in missions.All)
                {
                    if (!m.IsCompleted)
                    {
                        Console.WriteLine(this + "需要完成任务：“" + m.Name + "”");
                    }
                }

                if (!missions.转职.IsCompleted) { GameHelper.RunGameThread(RunTask转职); return; }
                if (!missions.转职_帝王之书.IsCompleted) { GameHelper.RunGameThread(RunTask转职_帝王之书); return; }
                if (!missions.转职_先知之魂.IsCompleted) { GameHelper.RunGameThread(RunTask转职_先知之魂); return; }
                if (!missions.色即是空.IsCompleted) { GameHelper.RunGameThread(RunTask色即是空); return; }
                if (!missions.破损的魔导师铠甲.IsCompleted) { GameHelper.RunGameThread(RunTask破损的魔导师铠甲); return; }
                if (!missions.使用微端登录.IsCompleted) { GameHelper.RunGameThread(RunTask使用微端登录); return; }
                if (!missions.快速升级.IsCompleted) { GameHelper.RunGameThread(() => { RunTask快速升级(); }); return; }

                StartTradeTimer();
                GameHelper.RunGameThread(PlayAutoFight);
            });
            return true;
        }
        #endregion

        #region 任务方法
        public void RunTask转职()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            bool playAutoFight = true;
            if (!Monitor.TryEnter(missions.转职, 10)) { return; }
            var mission = missions.转职;
            currentRunMission = mission;

            try
            {
                if (missions.转职.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);

                Transmit(Maps.GetMap("冰风谷"));
                GoTo(196, 153);
                GoTo(173, 165);
                DateTime begin = DateTime.Now;

                while (gameEntered && !cancelOperation)
                {
                    if (this.CurrentMap.Name == "冰风谷" && (this.Location.X == 173 && this.Location.Y == 165))
                    {
                        ConsoleBLL.WriteLineWaring(this + " 已到达任务NPC");
                        break;
                    }
                    Thread.Sleep(100);
                    if ((DateTime.Now - begin).TotalSeconds > missionMoveTimeout)
                    {
                        ConsoleBLL.WriteLineWaring(this + "未到达任务NPC，放弃任务...timeout:" + missionMoveTimeout);
                        return;
                    }
                }
                engine.SendData(mission.GetCompletedData());
                if (WaitMissionComplete())
                {
                    ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name); playAutoFight = false;
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.转职);
                if (playAutoFight) { GameHelper.RunGameThread(PlayAutoFight); }
                else
                {
                    GameHelper.RunGameThread(RunTask转职_帝王之书);
                }
            }
        }

        public void RunTask转职_帝王之书()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            bool playAutoFight = true;
            if (!Monitor.TryEnter(missions.转职_帝王之书, 10)) { return; }
            var mission = missions.转职_帝王之书;
            currentRunMission = mission;

            try
            {
                if (missions.转职_帝王之书.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);
                engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00, 0x8C, 0xDA, 0x9A, 0x0C, 0x88, 0x05, 0x5C, 0x00, 0x00, 0xC2, 0xA9, 0x07 });//帝王之书传送
                Thread.Sleep(100);
                engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x8B, 0x57, 0x80, 0x1E, 0xD4, 0x0F });//进入地图
                Thread.Sleep(100);

                DateTime begin = DateTime.Now;
                while (gameEntered && !cancelOperation)
                {
                    if (this.CurrentMap.Name == "亚特兰蒂斯")
                    {
                        ConsoleBLL.WriteLineWaring(this + " 已到达任务地图");
                        break;
                    }
                    Thread.Sleep(100);
                    if ((DateTime.Now - begin).TotalSeconds > missionMoveTimeout)
                    {
                        ConsoleBLL.WriteLineWaring(this + " 未到达任务地图，放弃任务...timeout:" + missionMoveTimeout);
                        GameHelper.RunGameThread(PlayAutoFight);
                        return;
                    }
                }

                if (!gameEntered || cancelOperation) { return; }

                ConsoleBLL.WriteLineInfo(this + " 开始打一转任务物品：帝王之书");
                GameHelper.RunGameThread(StartAutoFight);
                while (gameEntered && !cancelOperation)
                {
                    Thread.Sleep(1000);
                    lock (Items)
                    {
                        var item = Items.FirstOrDefault(f => f.Name == "帝王之书");
                        if (item != null)
                        {
                            ConsoleBLL.WriteLineInfo(this + " 已经打到帝王之书");
                            if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                            Thread.Sleep(2000);
                            Transmit(Maps.GetMap("冰风谷"));
                            GoTo(196, 153); GoTo(173, 165);
                            engine.SendData(mission.GetCompletedData());
                            if (WaitMissionComplete())
                            {
                                ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name); playAutoFight = false; Items.Remove(item);
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.转职_帝王之书);
                if (playAutoFight) { GameHelper.RunGameThread(PlayAutoFight); }
                else
                {
                    GameHelper.RunGameThread(RunTask转职_先知之魂);
                }
            }
        }

        public void RunTask转职_先知之魂()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            if (!Monitor.TryEnter(missions.转职_先知之魂, 10)) { return; }
            var mission = missions.转职_先知之魂;
            currentRunMission = mission;

            try
            {
                if (missions.转职_先知之魂.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);

                engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x10, 0x00, 0x02, 0x00, 0x8C, 0xDA, 0x9A, 0x0C, 0xB8, 0x06, 0xFC, 0x02, 0x00, 0x00, 0xC6, 0xA9, 0x07 });//先知之魂传送
                Thread.Sleep(100);
                EnterMap();
                Thread.Sleep(100);

                DateTime begin = DateTime.Now;
                while (gameEntered && !cancelOperation)
                {
                    if (this.CurrentMap.Name == "亚特兰蒂斯")
                    {
                        ConsoleBLL.WriteLineWaring(this + " 已到达任务地图");
                        break;
                    }
                    Thread.Sleep(100);
                    if ((DateTime.Now - begin).TotalSeconds > missionMoveTimeout)
                    {
                        ConsoleBLL.WriteLineWaring(this + "未到达任务地图，放弃任务...timeout:" + missionMoveTimeout);
                        GameHelper.RunGameThread(PlayAutoFight);
                        return;
                    }
                }

                if (!gameEntered || cancelOperation) { return; }

                ConsoleBLL.WriteLineInfo(this + " 开始打一转任务物品：先知之魂");
                GameHelper.RunGameThread(StartAutoFight);
                while (gameEntered && !cancelOperation)
                {
                    Thread.Sleep(1000);
                    lock (Items)
                    {
                        var item = Items.FirstOrDefault(f => f.Name == "先知之魂");
                        if (item != null)
                        {
                            ConsoleBLL.WriteLineInfo(this + " 已经打到先知之魂");
                            if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                            Thread.Sleep(2000);
                            Transmit(Maps.GetMap("冰风谷"));
                            GoTo(196, 153);
                            GoTo(173, 165);

                            engine.SendData(mission.GetCompletedData());
                            if (WaitMissionComplete())
                            {
                                ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name); Items.Remove(item);
                            }
                            break;
                        }
                    }
                }
                if (LogDebugInfo)
                {
                    ConsoleBLL.WriteLineInfo(this + currentRunMission.Name + " 任务检测已结束");
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.转职_先知之魂);
                GameHelper.RunGameThread(PlayAutoFight);
            }
        }

        public void RunTask色即是空()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            bool playAutoFight = true;
            if (!Monitor.TryEnter(missions.色即是空, 10)) { return; }
            var mission = missions.色即是空;
            currentRunMission = mission;

            try
            {
                if (missions.色即是空.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);
                Transmit(Maps.GetMap("死亡沙漠"));
                EnterMap();
                GoTo(190, 222);
                GoTo(180, 216);
                GoTo(170, 211);
                GoTo(153, 205);
                GoTo(139, 210);
                GoTo(119, 207);
                GoTo(122, 203);
                Thread.Sleep(100);
                EnterMap();
                DateTime begin = DateTime.Now;
                while (true)
                {
                    if (this.CurrentMap.Name == "死亡沙漠" && (this.Location.X == 122 && this.Location.Y == 203))
                    {
                        ConsoleBLL.WriteLineWaring(this + " 已到达任务怪地图，开始打怪");
                        break;
                    }
                    Thread.Sleep(100);
                    if ((DateTime.Now - begin).TotalSeconds > missionMoveTimeout)
                    {
                        ConsoleBLL.WriteLineWaring(this + "未到达任务怪地图，放弃任务...timeout:" + missionMoveTimeout);
                        return;
                    }
                }

                int lastKilled = KilledCount;
                var taskComplet = false;
                ConsoleBLL.WriteLine(this + " 开始色即是空任务打怪");
                GameHelper.RunGameThread(StartAutoFight);

                begin = DateTime.Now;
                while (gameEntered && !cancelOperation)
                {
                    Thread.Sleep(300);
                    if (KilledCount - lastKilled > 65) { taskComplet = true; break; }
                    if ((DateTime.Now - begin).TotalMinutes > 60)
                    {
                        ConsoleBLL.WriteLineWaring(this + " 60分钟内未杀完任务怪，结束检测任务怪击杀数量");
                        return;
                    }
                }

                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                if (taskComplet)
                {
                    if (!(GoTo(122, 203) && GoTo(131, 188) && GoTo(148, 177)))
                    {
                        ConsoleBLL.WriteLineWaring(this + " 移动到npc失败，放弃任务..."); return;
                    }
                    Thread.Sleep(100);
                    engine.SendData(mission.GetCompletedData());

                    if (WaitMissionComplete())
                    {
                        ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name); playAutoFight = false;
                    }
                }
                else
                {
                    ConsoleBLL.WriteLine(this + " 色即是空任务超时");
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.色即是空);
                if (playAutoFight) { GameHelper.RunGameThread(PlayAutoFight); }
                else
                {
                    GameHelper.RunGameThread(RunTask破损的魔导师铠甲);
                }
            }
        }

        public void RunTask破损的魔导师铠甲()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            var playAutoFight = true;
            if (!Monitor.TryEnter(missions.破损的魔导师铠甲, 10)) { return; }
            currentRunMission = missions.破损的魔导师铠甲;
            var mission = currentRunMission;

            try
            {
                if (missions.破损的魔导师铠甲.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);
                Transmit(Maps.GetMap("死亡沙漠"));
                var success = GoTo(190, 222) &
                GoTo(180, 216) &
                GoTo(170, 211) &
                GoTo(153, 205) &
                GoTo(139, 210) &
                GoTo(119, 207) &
                GoTo(122, 203);

                if (!success || this.CurrentMap.Name != "死亡沙漠")
                {
                    ConsoleBLL.WriteLineWaring(this + " 未到达任务怪地图，放弃任务");
                    return;
                }
                Thread.Sleep(100);
                EnterMap();
                var taskComplete = false;
                int lastKilled = KilledCount;
                ConsoleBLL.WriteLine(this + " 开始破损的魔导师铠甲任务打怪");
                GameHelper.RunGameThread(StartAutoFight);
                while (!AutoFight)//等待打怪任务开始
                {
                    Thread.Sleep(500);
                    if (!gameEntered || cancelOperation) { return; }
                }

                var begin = DateTime.Now;
                while (gameEntered && !cancelOperation)
                {
                    var item = Items.Where(c => c.Name == "破损的魔导师铠甲").Sum(c => c.Count);
                    if (item >= 5)
                    {
                        ConsoleBLL.WriteLineInfo(this + " 破损的魔导师铠甲已收集5个");
                        taskComplete = true; break;
                    }
                    Thread.Sleep(1000);
                    if ((DateTime.Now - begin).TotalMinutes % 5 == 0)//每5分钟整理背包一次
                    {
                        CleanPackage();
                    }
                    if ((DateTime.Now - begin).TotalMinutes > 60)
                    {
                        ConsoleBLL.WriteLineWaring(this + " 60分钟内未打够任务物品，结束任务");
                        return;
                    }
                }

                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }

                if (taskComplete)
                {
                    if (!(GoTo(122, 203) && GoTo(131, 188) && GoTo(148, 177)))
                    {
                        ConsoleBLL.WriteLineWaring(this + " 移动到npc失败，放弃任务...");
                        return;
                    }
                    Thread.Sleep(100);
                    engine.SendData(mission.GetCompletedData());

                    if (WaitMissionComplete())
                    {
                        ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name);
                        CleanPackage();
                        playAutoFight = false;
                    }
                }
                else
                {
                    ConsoleBLL.WriteLine(this + " 破损的魔导师铠甲任务超时");
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.破损的魔导师铠甲);
                if (playAutoFight) { GameHelper.RunGameThread(PlayAutoFight); }
                else
                {
                    GameHelper.RunGameThread(RunTask使用微端登录);
                }
            }
        }

        public void RunTask使用微端登录()
        {
            if (taskRunning) { return; }
            taskRunning = true;
            if (!Monitor.TryEnter(missions.使用微端登录, 10)) { return; }
            currentRunMission = missions.使用微端登录;
            var mission = currentRunMission;
            bool playAutoFight = true;

            try
            {
                if (missions.使用微端登录.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);
                Transmit(Maps.GetMap("勇者大陆"));
                GoTo(407, 167);
                Thread.Sleep(100);
                EnterMap();
                DateTime begin = DateTime.Now;

                while (gameEntered && !cancelOperation)
                {
                    if (this.CurrentMap.Name == "勇者大陆" && (this.Location.X == 407 && this.Location.Y == 167))
                    {
                        ConsoleBLL.WriteLineWaring(this + " 已到达玛雅哥布林"); break;
                    }
                    Thread.Sleep(100);
                    if ((DateTime.Now - begin).TotalSeconds > 30)
                    {
                        ConsoleBLL.WriteLineWaring(this + " 未到玛雅哥布林，放弃任务...timeout:" + missionMoveTimeout); return;
                    }
                }

                engine.SendData(mission.GetCompletedData());
                if (WaitMissionComplete())
                {
                    ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name);
                    Get贵宾礼包();//获取175绑钻
                    Thread.Sleep(3000);
                    Buy黑龙波(); Thread.Sleep(1000);
                    playAutoFight = false;
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.使用微端登录);
                if (playAutoFight) { GameHelper.RunGameThread(PlayAutoFight); }
                else
                {
                    GameHelper.RunGameThread(() => { RunTask快速升级(true); });
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="skipMove">跳过移动</param>
        public void RunTask快速升级(bool skipMove = false)
        {
            if (taskRunning) { return; }
            if (!Monitor.TryEnter(missions.快速升级, 10)) { return; }
            taskRunning = true;
            currentRunMission = missions.快速升级;
            var mission = currentRunMission;

            try
            {
                if (missions.快速升级.IsCompleted) { return; }
                if (!StopRunScript(PlayerStatusEnum.游戏中)) { return; }
                ConsoleBLL.WriteLineInfo(this + "开始执行任务：" + mission.Name);

                if (!skipMove)
                {
                    Transmit(Maps.GetMap("勇者大陆"));
                    GoTo(407, 167);
                    Thread.Sleep(100);
                    EnterMap();
                    DateTime begin = DateTime.Now;

                    while (gameEntered && !cancelOperation)
                    {
                        if (this.CurrentMap.Name == "勇者大陆" && (this.Location.X == 407 && this.Location.Y == 167))
                        {
                            ConsoleBLL.WriteLineWaring(this + " 已到达玛雅哥布林"); break;
                        }
                        Thread.Sleep(100);
                        if ((DateTime.Now - begin).TotalSeconds > 30)
                        {
                            ConsoleBLL.WriteLineWaring(this + "未到玛雅哥布林，放弃任务...timeout:" + missionMoveTimeout); return;
                        }
                    }
                }

                engine.SendData(mission.GetCompletedData());
                if (WaitMissionComplete())
                {
                    ConsoleBLL.WriteLineInfo(this + "完成任务：" + mission.Name);
                    Thread.Sleep(1000);
                    ConsoleBLL.WriteLineInfo(this + "开始强化翅膀...");
                    if (currentWing == null)
                    {
                        ConsoleBLL.WriteLineWaring(this + " 翅膀为空，无法强化");
                        return;
                    }
                    for (var i = 0; i < 6; i++)
                    {
                        Action强化装备(currentWing);
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError(ex.Message);
            }
            finally
            {
                ConsoleBLL.WriteLineInfo(this + "结束执行任务：" + mission.Name);
                taskRunning = false;
                currentRunMission = null;
                Monitor.Exit(missions.快速升级);
                GameHelper.RunGameThread(PlayAutoFight);
            }
        }
        #endregion

        #region 领取物品
        public void Get开学礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取开学礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0xCC, 0xE3, 0x84, 0x04, 0x00 });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get50级礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取50级礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x28, 0x8C, 0x0E });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get100级礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取100级礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x28, 0x8C, 0x0C });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get150级礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取150级礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x28, 0x8C, 0x0A });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get175级礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取175级礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x28, 0x8C, 0x0A });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get200级礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取200级礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x28, 0x8C, 0x08 });
            Thread.Sleep(1000);
            OpenMailBox();
        }

        public void Get微信礼包()
        {
            if (LogDebugInfo)
            {
                ConsoleBLL.WriteLineInfo(this + "领取微信礼包");
            }
            engine.SendData(new byte[] { 0x00, 0x00, 0x00, 0x0A, 0x00, 0x08, 0x98, 0x02, 0x00, 0x04, 0x33, 0x37, 0x33, 0x37 });
            Thread.Sleep(1000);
            OpenMailBox();
        }
        #endregion

        public bool WaitMissionComplete()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            while (gameEntered && !cancelOperation)
            {
                if (currentRunMission.IsCompleted) { break; }
                Thread.Sleep(100);
                if (watch.Elapsed.TotalSeconds > 30)
                {
                    ConsoleBLL.WriteLineWaring(this + "等待完成任务【" + currentRunMission.Name + "】超时");
                    break;
                }
            }
            if (currentRunMission.IsCompleted)
            {
                ConsoleBLL.WriteLineInfo(this + "完成任务：" + currentRunMission.Name);
            }
            return currentRunMission.IsCompleted;
        }
    }
}
